<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include::header"></head>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<!-- <div class="ibox-title">
						<h5>图片上传</h5>
					</div> -->
					<div class="ibox-content">
						<div class="form-horizontal m-t" id="signupForm">
							<input id="inputId" name="inputId" th:value="${inputId}" type="hidden">
							<input id="imgId" name="imgId" th:value="${imgId}" type="hidden">
							<div class="form-group">
								<label class="col-sm-2 control-label"></label>
								<div class="col-sm-8">
									<input id="fileupload" name="file" class="file-loading" multiple  
										type="file" data-min-file-count="0" 
										data-browse-on-zone-click="true" accept="image/*">
								</div>
							</div>

							<div class="form-group text-center">
								<div class="col-sm-8 col-sm-offset-2">
									<div class="btn btn-danger" onclick="closeDow()"><i class="fa fa-remove"></i> 关闭</div>
								</div>
							</div>
							<input type="hidden" id="domId" name="domId" th:value="${domId}">
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:include="include::footer"></div>
	<script type="text/javascript" src="/js/plugins/bootstrap-fileinput/fileinput.min.js"></script>
	<script type="text/javascript" src="/js/plugins/bootstrap-fileinput/locales/zh.js"></script>
	<script type="text/javascript">
		/**
		 * Created by kanghaixin on 2016/11/23.
		 */
		var result = [];
		var url = '/platform/config/upload2';
		$(function () {
			$("#fileupload").fileinput({
				showCaption: false,
				dropZoneEnabled: true,
				language:'zh',
				uploadUrl: url,
				allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
				minFileCount:0,
				maxFileCount: 100,
				enctype: 'multipart/form-data',
				showUpload: true, //是否显示上传按钮
				browseClass: "btn btn-primary", //按钮样式             
				previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
				msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
			}).on("fileuploaded", function (event, data, previewId, index){
                var size = data.files.length;
				var response = data.response;
				if (response) {
					if (response.code === 0) {
						result.push(response.key) ;
					}else if(result.code == -1){
						parent.layer.msg(result.msg,{icon:7})
					}
				}
				if (result.length  >= size) {
					console.log("img url:"+ result);
					/**
					 * 调用父类方法传递数据
					 */
					var domId = $('#domId').val();
					parent.loadImgsInfo(domId,result);
					closeDow();
				}
			});
		});
	</script>
	<script type="text/javascript">
		function closeDow() {
			var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
			parent.layer.close(index);
		}
	</script>
</body>

</html>
